<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
 <title>B4X JsonParseTool</title>
 <link rel="stylesheet" type="text/css" href="index.css" />
 <script src="jquery.min.js"></script>
 <script src="jquery.autosize.js"></script>
 </head>
 <body>
	<h1>B4X JsonParser</h1>
	<button id="btnParse" style="{width:200px}"> Parse </button>
	<div id="main">
		<div id="rawTextDiv">
			<textarea id="textarea">{a:"a",b:1,c:1.1,d:{a:"a",b:1}}</textarea>
		</div>
		<div id="treeDiv">
		</div>
		<textarea id="codeP">Build 20160615</textarea>
	</div>
	<script>
	$( document ).ready(function() {
		$("#textarea").autosize();
		$("#btnParse").click(function(e) {
			e.preventDefault();
			$.ajax({
				type: "POST",
				url: "jsonHelper",
				data: $("#textarea").val(), 
			   success: function(result)
			   {
				   if (result.success) {
						$("#codeP").html(result.code);
						 $("#treeDiv").html(result.tree);
						 $("ul li:last-child").addClass('last');
				   }
				   else {
						alert(result.error);
				   }
			   },
				error: function (xhr, ajaxOptions, thrownError) {
					alert(thrownError);
				}
			});
			
		});
		$("#textarea").focus(function() {
			var $this = $(this);
			$this.select();
			$this.mouseup(function() {
				$this.unbind("mouseup");
			return false;
			});
		});
		$("#codeP").focus(function() {
			var $this = $(this);
			$this.select();
			$this.mouseup(function() {
				$this.unbind("mouseup");
			return false;
			});
		});
	});
	</script>

 </body>
